<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="医疗机构名称" prop="medicalIdName">
        <el-input
          v-model="queryParams.medicalIdName"
          placeholder="请输入医疗机构名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="设备序列号" prop="code" >
        <el-input
          v-model="queryParams.code"
          placeholder="请输入设备编码序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:message:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="messageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="机构名称" align="center" prop="medicalIdName" />
      <el-table-column label="设备状态" align="center" prop="onoff">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_run_status" :value="scope.row.onoff"/>
        </template>
      </el-table-column>
      <el-table-column label="设备序列号" align="center" prop="code" />
      <el-table-column label="吸污泵状态" align="center" prop="inpumponoff">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_run_status" :value="scope.row.inpumponoff"/>
        </template>
      </el-table-column>
      <el-table-column label="排污泵状态" align="center" prop="outpumponoff">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_run_status" :value="scope.row.outpumponoff"/>
        </template>
      </el-table-column>
      <el-table-column label="臭氧状态" align="center" prop="ozoneonoff">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_run_status" :value="scope.row.ozoneonoff"/>
        </template>
      </el-table-column>
      <el-table-column label="循环泵状态" align="center" prop="sterilizetime">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_run_status" :value="scope.row.sterilizetime"/>
        </template>
      </el-table-column>
      <el-table-column label="纯净水缺水" align="center" prop="clearwaterlow">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_bj_status" :value="scope.row.clearwaterlow"/>
        </template>
      </el-table-column>
      <el-table-column label="纯净水水位高" align="center" prop="clearwaterhigh">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_bj_status" :value="scope.row.clearwaterhigh"/>
        </template>
      </el-table-column>
      <el-table-column label="吸污泵运行超时" align="center" prop="xiwubengbaojing">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_bj_status" :value="scope.row.xiwubengbaojing"/>
        </template>
      </el-table-column>
      <el-table-column label="排污泵运行超时" align="center" prop="paiwubengbaojing">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equipment_bj_status" :value="scope.row.paiwubengbaojing"/>
        </template>
      </el-table-column>
      <el-table-column label="报警时间" align="center" prop="baojingtime" :formatter="formartData"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:message:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listMessage, getMessage, delMessage, addMessage, updateMessage } from "@/api/system/message";

export default {
  name: "Message",
  dicts: ['equipment_run_status','equipment_bj_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备告警信息表格数据
      messageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        medicalId: null,
        medicalIdName:null,
        code:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备告警信息列表 */
    getList() {
      this.loading = true;
      listMessage(this.queryParams).then(response => {
        this.messageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    formartData(data){
      let date = new Date(Number(data.baojingtime));
      let Y = date.getFullYear() + '-';
      let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      let D = date.getDate() + ' ';
      let h = date.getHours() + ':';
      let m = date.getMinutes() + ':';
      let s = date.getSeconds(); 
      return Y+M+D+h+m+s;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        medicalId: null,
        medicalIdName:null,
        code:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除设备告警信息编号为"' + ids + '"的数据项？').then(function() {
        return delMessage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/message/export', {
        ...this.queryParams
      }, `message_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
